//
//  MYNewsShopDetailsScenicspotTickerCell.swift
//  MuYing
//
//  Created by tbb on 2020/3/10.
//  Copyright © 2020 TBB. All rights reserved.
//

import UIKit

class MYNewsShopDetailsScenicspotTickerCell: YQTableViewBaseCell {
    
    @objc var selectNumBlock:((_ :NSString)->())?
    
    @IBOutlet weak var titleLb: UILabel!
    
    @IBOutlet weak var specificationLb: UILabel!
    @IBOutlet weak var priceLb: UILabel!
    
    @IBOutlet weak var numLb: UILabel!
    @IBOutlet weak var addBtn: UIButton!
    @IBOutlet weak var subtractBtn: UIButton!
    override func awakeFromNib() {
        super.awakeFromNib()
        self.addBtn.addTarget(self, action: #selector(numWith(_:)), for: UIControl.Event.touchUpInside)
        self.subtractBtn.addTarget(self, action: #selector(numWith(_:)), for: UIControl.Event.touchUpInside)
    }
    
    override func layoutSubviews() {
        super.layoutSubviews();
        self.addBtn.layer.cornerRadius = 10;
        self.subtractBtn.layer.cornerRadius = 10;
    }
    
    @objc private func numWith(_ sender:UIButton) {
        guard var num = Int(self.numLb.text ?? "1") else { return };
        
        if sender == self.addBtn {
            num += 1;
        }else{
            if num > 1 {
                num -= 1;
            }
        }
        self.numLb.text = String(format: "%zd", num);
        if let selectNumBlock = self.selectNumBlock {
            selectNumBlock(self.numLb?.text as NSString? ?? "1");
        }
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
